package FenxiaoService

import (
	"context"
	toolsDb "gdshop-back-end-go/common/db"
	"gdshop-back-end-go/common/libs/myCache"
	"gdshop-back-end-go/common/response/FenxiaoResp"
	"github.com/gogf/gf/util/gconv"
	"time"
)

func BaseGetConfig() (*FenxiaoResp.GetConfig, error) {
	var data *FenxiaoResp.GetConfig
	value, err := myCache.GetOrSetFunc("sysConfigValue:"+fenxiaoConfigKey, func() (interface{}, error) {
		nei, err := toolsDb.GetUnSafaTableAddDeleteWhere(context.Background(), "sys_config").Where(
			"config_key = ?", fenxiaoConfigKey).Value("config_value")
		if err != nil {
			return data, err
		}
		return nei.String(), nil
	}, 86400*time.Second)
	if err != nil {
		return nil, err
	}
	err = gconv.Scan(value, &data)
	if err != nil {
		return nil, err
	}
	return data, nil
}
